In [1]:
i=False
while not i:
a = 1
In [2]:
import numpy as np
In [3]:
a = 1
print a
In [4]:
print a
In [5]:
a = a + 1
In [6]:
print a
In [7]:
def myfunc(a):
x = a + 1
return x
myfunc(5)
Out[7]:
In [8]:
%matplotlib inline
In [9]:
import seaborn as sns
sns.set(style="ticks")
# Load the example tips dataset
tips = sns.load_dataset("tips")
# Draw a nested boxplot to show bills by day and sex
ax = sns.boxplot(x="day", y="total_bill", hue="sex", data=tips, palette="PRGn")
sns.despine(offset=10, trim=True)
In [10]:
ax.get_figure().savefig('test.pdf')
In [11]:
import pandas as pd
mat = pd.read_csv('test.csv')
mat
Out[11]:
In [12]:
callback = ! ls -lrt
print callback
In [13]:
cmd = 'ls {}'.format('-lrt') ## The shell command you wish to execute
callback = ! $cmd
print callback
In [14]:
import tensorflow as tf
In [15]:
# Load MNIST data
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
In [16]:
# Define the input as a "placeholder", as we will feed the value in later
x = tf.placeholder(tf.float32, [None, 784])
In [17]:
# Define the parameters in the network as "Variable", which the model will learn
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
In [18]:
# Define the output y as a symbolic variable, the value of which depends on x, W and b
y = tf.nn.softmax(tf.matmul(x, W) + b)
In [19]:
# Define the true label as "placeholder", as we will feed the value in later
y_true = tf.placeholder(tf.float32, [None, 10])
In [20]:
# Define the loss
# tf.reduce_sum: Computes the sum of elements across dimensions of a tensor.
# tf.reduce_mean Computes the mean of elements across dimensions of a tensor.
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_true * tf.log(y), reduction_indices=[1]))
In [21]:
# Define the task (optimize cross_entropy)
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
In [22]:
# Get the handle to initialization function
init = tf.initialize_all_variables()
In [23]:
# Define a "session" and run initialization
sess = tf.Session()
sess.run(init)
In [24]:
# Use this session to train on 1000 mini-baches of size 100
for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_true: batch_ys})
In [25]:
# Define symbolic variables that calculates accuracy
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_true,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
In [26]:
# Run the session with a test image and its correct label provided to fetch the accuracy in predicting it's label
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_true: mnist.test.labels}))
In [ ]: